package org.web.datajpa.controller;

import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.web.datajpa.domain.Student;
import org.web.datajpa.domain.Teacher;
import org.web.datajpa.service.StudentService;
import org.web.datajpa.service.TeacherService;

import java.util.List;

@RestController

public class HelloController {
    @Autowired
    public StudentService studentService;
    @Autowired
    public TeacherService teacherService;


    @Autowired
    public Gson gson;
    // 字符串形式返回所有学生
    @RequestMapping(value = "/student/all",method = RequestMethod.GET)
    public String findAllStudent() {
        List<Student> myAll = studentService.findAll();
        String jsonStr = gson.toJson(myAll);
        return jsonStr;
    }
    // 字符串形式返回所有老师
    @RequestMapping(value = "/teacher/all",method = RequestMethod.GET)
    public String findAllTeacher() {
        List<Teacher> myAll = teacherService.findAll();
        String jsonStr = gson.toJson(myAll);
        return jsonStr;
    }
}
